// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_ACCOUNTS
// * CreateDate    : 2012/2/2 10:17:12
// * Creater       : CodeSmith
// * LastChangeDate: 2012/2/2 10:17:12
// * LastChanger   : 2012/2/2 10:17:12
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinAccounts
    /// </summary>
    public partial class FinAccountsBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinAccountsEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinAccountsEntity GetFinAccounts(FinAccountsEntity objFinAccountsEntity)
        {
            return DataAccess.SelectSingle<FinAccountsEntity>(objFinAccountsEntity);
        }

        public static FinAccountsEntity GetByCode(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return null;
            }
            FinAccountsEntity entity = new FinAccountsEntity();
            entity.AccountsCode = code;
            return DataAccess.SelectSingle<FinAccountsEntity>(entity);
        }

        public static FinAccountsEntity GetParentByCode(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return null;
            }
            string sql = @"SELECT P.* 
                            FROM FIN_ACCOUNTS A 
                            INNER JOIN FIN_ACCOUNTS P ON P.ACCOUNTS_CODE = A.PARENT_CODE
                            WHERE A.ACCOUNTS_CODE = '" + code + "'";
            List<FinAccountsEntity> list = DataAccess.Select<FinAccountsEntity>(sql);
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            return null;
        }

        public static List<FinAccountsEntity> GetByType(string type)
        {
            if (string.IsNullOrEmpty(type))
            {
                return null;
            }
            FinAccountsEntity entity = new FinAccountsEntity();
            entity.AccountsType = type;
            return DataAccess.Select<FinAccountsEntity>(entity);
        }

        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"A.*, P.ACCOUNTS_NAME AS PARENT_NAME
                            FROM FIN_ACCOUNTS A
                            LEFT JOIN FIN_ACCOUNTS P ON P.ACCOUNTS_CODE = A.PARENT_CODE
                            WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }

        public static DataTable GetAccountsType()
        {
            string sql = "SELECT ACCOUNTS_TYPE FROM FIN_ACCOUNTS GROUP BY ACCOUNTS_TYPE";
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinAccountsEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinAccounts(FinAccountsEntity objFinAccountsEntity)
        {
            return DataAccess.Insert(objFinAccountsEntity);
        }

        public static bool InsertFinAccounts(List<FinAccountsEntity> objFinAccountsEntityList)
        {
            return DataAccess.Insert(objFinAccountsEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinAccountsEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinAccounts(FinAccountsEntity objFinAccountsEntity)
        {
            return DataAccess.Update(objFinAccountsEntity);
        }

        public static bool UpdateFinAccounts(List<FinAccountsEntity> objFinAccountsEntityList)
        {
            return DataAccess.Update<FinAccountsEntity>(objFinAccountsEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinAccountsEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinAccounts(FinAccountsEntity objFinAccountsEntity)
        {
            return DataAccess.Delete(objFinAccountsEntity);
        }

        public static bool DeleteFinAccounts(List<FinAccountsEntity> objFinAccountsEntityList)
        {
            return DataAccess.Delete<FinAccountsEntity>(objFinAccountsEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinAccountsAll()
        {
            return DataAccess.SelectAllDataSet<FinAccountsEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinAccountsEntity> GetFinAccountsAllList()
        {
            return DataAccess.SelectAll<FinAccountsEntity>();
        }
        #endregion
	}
	
	
}	

